<?php
class Common
{
	public function randomCode() {
    	$chars = "abcdefghijkmnopqrstuvwxyz023456789";
    	srand((double)microtime()*1000000);
    	$i = 0;
    	$pass = '' ;
    	while ($i <= 7) {
        	$num = rand() % 33;
        	$tmp = substr($chars, $num, 1);
        	$pass = $pass . $tmp;
        	$i++;
    	}
    	return $pass;
	}
	
	public function getCategoryBySubCat($subcat)
	{
		$sql1 = "SELECT cat_desc AS CAT 
				FROM tbl_category 
				WHERE cat_id IN 
					(SELECT parent_id 
						FROM tbl_category 
						WHERE cat_id = " . $subcat . "
					)
				";
		
		$qry1 = DB::fetchRow($sql1);
		
		$sql2 = "SELECT parent_id, cat_desc AS SUBCAT 
				 FROM tbl_category 
				 WHERE cat_id = " . $subcat;
		
		$qry2 = DB::fetchRow($sql2);
		$parent_id = $qry2['parent_id'];
		
		if($qry1['CAT'] == "" && $qry2['SUBCAT'] == "") 
		{
			return "Home";
		} else if($qry1['CAT'] != "") {
			return "<a href='" . SITEURL . "'>Home</a> :: <a href='" . SITEURL . "index.php/?viewproducts/cat/" . $parent_id . "'>" . $qry1['CAT'] . "</a> :: " . $qry2['SUBCAT']; 
		} else {
			return "<a href='" . SITEURL . "'>Home</a> :: " . $qry2['SUBCAT'];
		}
	}
}
?>